﻿@using MrCMS.Installation
@model MrCMS.Installation.InstallModel
@{
    ViewBag.Title = "Install MrCMS";
    Layout = "~/Views/Shared/_Installation.cshtml";
    var installationResult = ViewData["installationResult"] as InstallationResult;
    var providerTypes = ViewData["provider-types"] as List<DatabaseProviderInfo> ?? new List<DatabaseProviderInfo>();
}

@using (Html.BeginForm("Setup", "Install", FormMethod.Post, new { id = "installationform" }))
{
    if (installationResult != null)
    {
        if (installationResult.Errors.Any())
        {
            <div class="alert alert-danger">
                <strong>Sorry there was a problem installing - please see errors below</strong>
                <ul>
                    @{
            foreach (var error in installationResult.Errors)
            {
                <li>@error</li>
            }
                    }
                </ul>
            </div>
        }
    }
    <div class="row">
        <div class="col-lg-6">
            <fieldset>
                <h4>Site Information</h4>
                <hr class="small-margin" />

                <div class="form-group">
                    @Html.LabelFor(x => x.SiteName)
                    @Html.TextBoxFor(x => x.SiteName, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.SiteName)
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.SiteUrl)
                    @Html.TextBoxFor(x => x.SiteUrl, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.SiteUrl)
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.AdminEmail)
                    @Html.TextBoxFor(x => x.AdminEmail, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.AdminEmail)
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.AdminPassword)
                    @Html.PasswordFor(x => x.AdminPassword, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.AdminPassword)
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.ConfirmPassword)
                    @Html.PasswordFor(x => x.ConfirmPassword, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.ConfirmPassword)
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.UiCulture)
                    @Html.DropDownListFor(x => x.UiCulture, Model.CultureOptions, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.UiCulture)
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.TimeZone)
                    @Html.DropDownListFor(x => x.TimeZone, Model.TimeZoneOptions, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.TimeZone)
                </div>

            </fieldset>
        </div>
        <div class="col-lg-6">
            <fieldset>
                <h4>Database information</h4>
                <hr class="small-margin" />

                @foreach (var providerType in providerTypes)
                {
                    <div class="form-group">
                        <label class="radio-inline">
                            @Html.RadioButton("DatabaseProvider", providerType.TypeName, (Model.DatabaseProvider == providerType.TypeName), new { data_connection_string_required = providerType.RequiresConnectionStringBuilding })
                            @providerType.Description
                        </label>
                    </div>
                }
                <hr />

                <div id="sqlConnectionInfo">

                    <div class="form-group">
                        <label class="checkbox-inline">
                            @Html.CheckBoxFor(x => x.SqlServerCreateDatabase)
                            Create database if it doesn't exist
                        </label>
                    </div>

                    <div class="form-group">
                        <label class="radio-inline">
                            @Html.RadioButton("SqlConnectionInfo", SqlConnectionInfo.Values, (Model.SqlConnectionInfo == SqlConnectionInfo.Values), new { id = "sqlconnectioninfo_values" })
                            Enter SQL connection values
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="radio-inline">
                            @Html.RadioButton("SqlConnectionInfo", SqlConnectionInfo.Raw, (Model.SqlConnectionInfo == SqlConnectionInfo.Raw), new { id = "sqlconnectioninfo_raw" })
                            Enter raw connection string (advanced)
                        </label>
                    </div>

                    <div id="sqlDatabaseInfo">

                        <div class="form-group">
                            @Html.LabelFor(x => x.SqlServerName)
                            @Html.TextBoxFor(x => x.SqlServerName, new { @class = "form-control" })
                            @Html.ValidationMessageFor(x => x.SqlServerName)
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(x => x.SqlDatabaseName)
                            @Html.TextBoxFor(x => x.SqlDatabaseName, new { @class = "form-control" })
                            @Html.ValidationMessageFor(x => x.SqlDatabaseName)
                        </div>

                        <div class="form-group">
                            <label class="radio-inline">
                                @Html.RadioButton("SqlAuthenticationType", SqlAuthenticationType.SQL, (Model.SqlAuthenticationType == SqlAuthenticationType.SQL), new { id = "sqlauthenticationtype_sql" })
                                Use SQL Server account
                            </label>
                        </div>

                        <div class="form-group">
                            <label class="radio-inline">
                                @Html.RadioButton("SqlAuthenticationType", SqlAuthenticationType.Windows, (Model.SqlAuthenticationType == SqlAuthenticationType.Windows), new { id = "sqlauthenticationtype_windows" })
                                Use integrated Windows authentication
                            </label>
                        </div>

                        <div class="form-group" id="pnlSqlServerUsername">
                            @Html.LabelFor(x => x.SqlServerUsername)
                            @Html.TextBoxFor(x => x.SqlServerUsername, new { @class = "form-control" })
                            @Html.ValidationMessageFor(x => x.SqlServerUsername)
                        </div>

                        <div class="form-group" id="pnlSqlServerPassword">
                            @Html.LabelFor(x => x.SqlServerPassword)
                            @Html.PasswordFor(x => x.SqlServerPassword, new { @class = "form-control" })
                            @Html.ValidationMessageFor(x => x.SqlServerPassword)
                        </div>

                    </div>
                    <div id="sqlDatabaseConnectionString">
                        <div class="form-group" id="pnlSqlServerUsername">
                            @Html.LabelFor(x => x.DatabaseConnectionString)
                            @Html.TextBoxFor(x => x.DatabaseConnectionString, new { @class = "form-control" })
                            @Html.ValidationMessageFor(x => x.DatabaseConnectionString)
                        </div>
                        <span class="hint">
                            Example:<br />
                            Data Source=sqlServerName;Initial Catalog=dbName;Persist Security Info=True;User
                            ID=userName;Password=password
                            <br />
                            Find more info <a href="http://www.connectionstrings.com/" target="_blank">here</a>
                        </span>
                    </div>
                </div>

            </fieldset>
        </div>
    </div>
    <hr />

    <div class="text-right">
        <input type="submit" value="Install" class="btn btn-lg btn-primary" />
    </div>

}